﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VoiceAI;
using VoiceAI.VoiceResponse;
using Windows.Data.Json;

namespace XiaoweiVoiceAI.ResponseCreators
{
    internal static class DriverListResponseCreator
    {
        private class DriverListResponseData : IDriverListResponseData
        {
            public string DriverName { get; set; }

            public ResponseType ResponseType => ResponseType.DriverList;

            public ErrorCode ErrorCode => ErrorCode.NoError;

            public string RequestText { get; set; }
            public string ResponseText { get; set; }
            public string TTSUrl { get; set; }

            public bool RestoreInHistory => true;

            public object DataContext { get; set; }
        }
        public static IResponseData CreateResponseData(XiaoweiVoiceAI xiaoweiVoiceAI, XiaoweiV2.ResponseParam param)
        {

            DriverListResponseData driverListResponseData = new DriverListResponseData();
            try
            {
                string name = "";
                string json = param.ResponseData;
                JsonObject jo = JsonObject.Parse(json);
                name = jo["slots"].GetArray()[0].GetObject()["norm"].GetString();
                driverListResponseData.DriverName = name;
            }
            catch
            {
                driverListResponseData.DriverName = "";
            }
            driverListResponseData.ResponseText = param.ResponseText;
            driverListResponseData.RequestText = param.RequestText;
            driverListResponseData.TTSUrl = XiaoweiV2.ResponseHelper.GetTTSUrl(param);
            return driverListResponseData;
        }
    }
}
